package com.gxuwz.check.action.admin;

import com.alibaba.fastjson.JSONObject;
import com.gxuwz.check.base.BaseAction;
import com.gxuwz.check.model.dto.ClassDto;
import com.gxuwz.check.model.entity.SysClassEntity;
import com.gxuwz.check.service.admin.IClassService;
import com.gxuwz.check.util.ResultJson;
import com.opensymphony.xwork2.ModelDriven;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class ClassAction extends BaseAction implements ModelDriven<SysClassEntity> {
    private SysClassEntity sysClassEntity = new SysClassEntity();
    @Override
    public SysClassEntity getModel() {
        return sysClassEntity;
    }

    @Autowired
    private IClassService classService;

    private int page; //当前页码

    private String className; //班级名称
    private int collegeId; //学院ID

    private int classId;

    /**
     * 获取所有班级
     */
    public void list() {

        List<ClassDto> list = classService.list(page);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        jsonObject.put("list",list);
        ResultJson.R(jsonObject);
    }

    /**
     * 删除班级
     */
    public void delete() {
        classService.delete(sysClassEntity.getClassId());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        ResultJson.R(jsonObject);
    }

    /**
     * 修改班级
     */
    public void edit() {

    }

    /**
     * 添加班级
     */
    public void save() {
        classService.save(sysClassEntity.getClassName(),sysClassEntity.getCollegeId());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        ResultJson.R(jsonObject);
    }

    /**ClassDto
     * 根据班级ID获班级信息
     */
    public void findClassById(){
        ClassDto classDto = classService.findClassById(sysClassEntity.getClassId());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code",20000);
        jsonObject.put("info",classDto);
        ResultJson.R(jsonObject);
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public int getCollegeId() {
        return collegeId;
    }

    public void setCollegeId(int collegeId) {
        this.collegeId = collegeId;
    }

    public int getClassId() {
        return classId;
    }

    public void setClassId(int classId) {
        this.classId = classId;
    }
}